package com.feishi.core.util.common;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2020-09-03
 * Time: 下午4:15
 */
public class RandomCount {
    public static void main(String[] args) throws InterruptedException {



        Map result=continuity(150000,150);
        System.out.println(result);
    }

    private static Map continuity(int i, int max) throws InterruptedException {
        boolean[] data=new boolean[i];
        for (int j = 0; j < i; j++) {
            data[j]=Math.random()>0.5;
            Thread.sleep(0,2);
        }
        Map<Integer,Integer> integerMap=new HashMap<>();
        int c=1;
        boolean b=data[0];
        for (int j = 1; j < i; j++) {
            if(data[j]==b){
                c++;
            }else {
                integerMap.put(Math.min(c,max),integerMap.getOrDefault(Math.min(c,max),0)+1);
                b=!b;
                c=1;
            }
        }
        integerMap.put(Math.min(c,max),integerMap.getOrDefault(Math.min(c,max),0)+1);
        return integerMap;
    }
}
